function PmatOut = Pmatrix(pStar, Pgrid, pstep)

% Calculates matrix P which indicates the split of adjusting firms' 
% mass between the two grid points around the optimal price  

nump = length(Pgrid);
PmatOut = zeros(nump,1);  % Pmat has zeros everywhere except around the diagonal, along the optimal price 

OPTindHI=find(Pgrid>pStar,1);
OPTindLO=max(OPTindHI-1,1);
PmatOut(OPTindHI,1)= (pStar-Pgrid(OPTindLO))/pstep;
PmatOut(OPTindLO,1)= (Pgrid(OPTindHI)-pStar)/pstep;    

